﻿Imports System.Data
Imports VSModel
Imports Cls_Common
Imports SecurityService
Partial Class Control_QuanLyMaSoThue_Edit
    Inherits System.Web.UI.UserControl
    Private Shared ReadOnly log As log4net.ILog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
#Region "Sub and Function "
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim script As ScriptManager = ScriptManager.GetCurrent(Me.Page)
            If Not script Is Nothing AndAlso script.IsInAsyncPostBack Then
                ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType, "jqueryEnable", "ajaxJquery()", True)
            Else
                Me.Page.ClientScript.RegisterStartupScript(Me.Page.GetType(), "jqueryEnable", String.Concat("Sys.Application.add_load(function(){", "ajaxJquery()", "});"), True)
            End If
            If Not Request.QueryString("Id").ToString.Equals("0") Then
                hidID.Value = Request.QueryString("Id")
                ShowData()
            End If
        End If
    End Sub
    Protected Sub ShowData()
        Using data As New VSEntities
            Dim p As NguoiNopThue = (From q In data.NguoiNopThues Where q.Id = hidID.Value Select q).SingleOrDefault
            If Not p Is Nothing Then
                txtMacqt.Text = IIf(IsNothing(p.MaCQT) = True, "", p.MaCQT)
                txtTencqt.Text = IIf(IsNothing(p.TenCQT) = True, "", p.TenCQT)
                txtSonguoinopthue.Text = IIf(IsNothing(p.SoNguoiNopThue) = True, "", p.SoNguoiNopThue)
                txtMasothue.Text = IIf(IsNothing(p.MaSoThue) = True, "", p.MaSoThue)
                txtTennguoinopthue.Text = IIf(IsNothing(p.TenNguoiNopThue) = True, "", p.TenNguoiNopThue)
                txtManganhchinh.Text = IIf(IsNothing(p.MaNganhChinh) = True, "", p.MaNganhChinh)
                txtTennganhchinh.Text = IIf(IsNothing(p.TenNganhChinh) = True, "", p.TenNganhChinh)
                txtSonha.Text = IIf(IsNothing(p.SoNha) = True, "", p.SoNha)
                txtMaphuongxa.Text = IIf(IsNothing(p.MaPhuongXa) = True, "", p.MaPhuongXa)
                txtTenphuongxa.Text = IIf(IsNothing(p.TenPhuongXa) = True, "", p.TenPhuongXa)
                txtMahuyen.Text = IIf(IsNothing(p.MaHuyen) = True, "", p.MaHuyen)
                txtHuyen.Text = IIf(IsNothing(p.Huyen) = True, "", p.Huyen)
                txtMatinh.Text = IIf(IsNothing(p.MaTinh) = True, "", p.MaTinh)
                txtTentinh.Text = IIf(IsNothing(p.TenTinh) = True, "", p.TenTinh)
                txtTongsolaodong.Text = IIf(IsNothing(p.TongSoLaoDong) = True, "", p.TongSoLaoDong)
                txtNganhnghe.Text = IIf(IsNothing(p.NganhNghe) = True, "", p.NganhNghe)
                txtTengiamdoc.Text = IIf(IsNothing(p.TenGiamDoc) = True, "", p.TenGiamDoc)
                txtDienthoaigiamdoc.Text = IIf(IsNothing(p.DienThoaiGiamDoc) = True, "", p.DienThoaiGiamDoc)
                txtSogiayto.Text = IIf(IsNothing(p.SoGiayTo) = True, "", p.SoGiayTo)
                txtNgaycap.Text = IIf(IsNothing(p.NgayCap) = True, "", p.NgayCap)
                txtLoaigiayto.Text = IIf(IsNothing(p.LoaiGiayTo) = True, "", p.LoaiGiayTo)
                txtSogcn.Text = IIf(IsNothing(p.SoGCN) = True, "", p.SoGCN)
                txtNgaycapgcn.Text = IIf(IsNothing(p.NgayCapGCN) = True, "", p.NgayCapGCN)
                txtCmnd.Text = IIf(IsNothing(p.CMND) = True, "", p.CMND)
                txtTenchuong.Text = IIf(IsNothing(p.TenChuong) = True, "", p.TenChuong)
                txtTenkhoan.Text = IIf(IsNothing(p.TenKhoan) = True, "", p.TenKhoan)
                txtLoainguoinopthue.Text = IIf(IsNothing(p.LoaiNguoiNopThue) = True, "", p.LoaiNguoiNopThue)
                txtMatrangthaidktcanhan.Text = IIf(IsNothing(p.MaTrangThaiDKTCaNhan) = True, "", p.MaTrangThaiDKTCaNhan)
                txtTrangthaidktcanhan.Text = IIf(IsNothing(p.TrangThaiDKTCaNhan) = True, "", p.TrangThaiDKTCaNhan)
                txtMatrangthaidkttochuc.Text = IIf(IsNothing(p.MaTrangThaiDKTToChuc) = True, "", p.MaTrangThaiDKTToChuc)
                txtTrangthaidkttochuc.Text = IIf(IsNothing(p.TrangThaiDKTToChuc) = True, "", p.TrangThaiDKTToChuc)
                txtNgaynhantokhai.Text = IIf(IsNothing(p.NgayNhanToKhai) = True, "", p.NgayNhanToKhai)
                txtLoaihinhkinhte.Text = IIf(IsNothing(p.LoaiHinhKinhTe) = True, "", p.LoaiHinhKinhTe)
                txtTamnghitungay.Text = IIf(IsNothing(p.TamNghiTuNgay) = True, "", p.TamNghiTuNgay)
                txtTamnghidenngay.Text = IIf(IsNothing(p.TamNghiDenNgay) = True, "", p.TamNghiDenNgay)
                txtLydotamnghi.Text = IIf(IsNothing(p.LyDoTamNghi) = True, "", p.LyDoTamNghi)
                txtLydodongmstcanhan.Text = IIf(IsNothing(p.LyDoDongMSTCaNhan) = True, "", p.LyDoDongMSTCaNhan)
                txtNgaydongtrangthaicanhan.Text = IIf(IsNothing(p.NgayDongTrangThaiCaNhan) = True, "", p.NgayDongTrangThaiCaNhan)
                txtLydodongmsttochuc.Text = IIf(IsNothing(p.LyDoDongMSTToChuc) = True, "", p.LyDoDongMSTToChuc)
                txtNgaydongtrangthaitochuc.Text = IIf(IsNothing(p.NgayDongTrangThaiToChuc) = True, "", p.NgayDongTrangThaiToChuc)
                txtQuoctich.Text = IIf(IsNothing(p.QuocTich) = True, "", p.QuocTich)
                txtNgaysinh.Text = IIf(IsNothing(p.NgaySinh) = True, "", p.NgaySinh)
                txtVonkinhdoanh.Text = IIf(IsNothing(p.VonKinhDoanh) = True, "", p.VonKinhDoanh)
                txtNguonvonnsnn.Text = IIf(IsNothing(p.NguonVonNSNN) = True, "", p.NguonVonNSNN)
                txtNguonvonnuocngoai.Text = IIf(IsNothing(p.NguonVonNuocNgoai) = True, "", p.NguonVonNuocNgoai)
                txtNguonvonkhac.Text = IIf(IsNothing(p.NguonVonKhac) = True, "", p.NguonVonKhac)
                txtNgaybatdaukinhdoanh.Text = IIf(IsNothing(p.NgayBatDauKinhDoanh) = True, "", p.NgayBatDauKinhDoanh)
                txtDienthoaiban.Text = IIf(IsNothing(p.DienThoaiBan) = True, "", p.DienThoaiBan)
            End If
        End Using
    End Sub
#End Region
#Region "Event for control"
    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Using data As New VSEntities
            Dim p As NguoiNopThue = (From q In data.NguoiNopThues Where q.Id = hidID.Value).SingleOrDefault
            Try
                p.Id = hidID.Value
                p.MaCQT = txtMacqt.Text.Trim()
                p.TenCQT = txtTencqt.Text.Trim()
                p.SoNguoiNopThue = txtSonguoinopthue.Text.Trim()
                p.MaSoThue = txtMasothue.Text.Trim()
                p.TenNguoiNopThue = txtTennguoinopthue.Text.Trim()
                p.MaNganhChinh = txtManganhchinh.Text.Trim()
                p.TenNganhChinh = txtTennganhchinh.Text.Trim()
                p.SoNha = txtSonha.Text.Trim()
                p.MaPhuongXa = txtMaphuongxa.Text.Trim()
                p.TenPhuongXa = txtTenphuongxa.Text.Trim()
                p.MaHuyen = txtMahuyen.Text.Trim()
                p.Huyen = txtHuyen.Text.Trim()
                p.MaTinh = txtMatinh.Text.Trim()
                p.TenTinh = txtTentinh.Text.Trim()
                p.TongSoLaoDong = txtTongsolaodong.Text.Trim()
                p.NganhNghe = txtNganhnghe.Text.Trim()
                p.TenGiamDoc = txtTengiamdoc.Text.Trim()
                p.DienThoaiGiamDoc = txtDienthoaigiamdoc.Text.Trim()
                p.SoGiayTo = txtSogiayto.Text.Trim()
                p.NgayCap = txtNgaycap.Text.Trim()
                p.LoaiGiayTo = txtLoaigiayto.Text.Trim()
                p.SoGCN = txtSogcn.Text.Trim()
                p.NgayCapGCN = txtNgaycapgcn.Text.Trim()
                p.CMND = txtCmnd.Text.Trim()
                p.TenChuong = txtTenchuong.Text.Trim()
                p.TenKhoan = txtTenkhoan.Text.Trim()
                p.LoaiNguoiNopThue = txtLoainguoinopthue.Text.Trim()
                p.MaTrangThaiDKTCaNhan = txtMatrangthaidktcanhan.Text.Trim()
                p.TrangThaiDKTCaNhan = txtTrangthaidktcanhan.Text.Trim()
                p.MaTrangThaiDKTToChuc = txtMatrangthaidkttochuc.Text.Trim()
                p.TrangThaiDKTToChuc = txtTrangthaidkttochuc.Text.Trim()
                p.NgayNhanToKhai = txtNgaynhantokhai.Text.Trim()
                p.LoaiHinhKinhTe = txtLoaihinhkinhte.Text.Trim()
                p.TamNghiTuNgay = txtTamnghitungay.Text.Trim()
                p.TamNghiDenNgay = txtTamnghidenngay.Text.Trim()
                p.LyDoTamNghi = txtLydotamnghi.Text.Trim()
                p.LyDoDongMSTCaNhan = txtLydodongmstcanhan.Text.Trim()
                p.NgayDongTrangThaiCaNhan = txtNgaydongtrangthaicanhan.Text.Trim()
                p.LyDoDongMSTToChuc = txtLydodongmsttochuc.Text.Trim()
                p.NgayDongTrangThaiToChuc = txtNgaydongtrangthaitochuc.Text.Trim()
                p.QuocTich = txtQuoctich.Text.Trim()
                p.NgaySinh = txtNgaysinh.Text.Trim()
                p.VonKinhDoanh = txtVonkinhdoanh.Text.Trim()
                p.NguonVonNSNN = txtNguonvonnsnn.Text.Trim()
                p.NguonVonNuocNgoai = txtNguonvonnuocngoai.Text.Trim()
                p.NguonVonKhac = txtNguonvonkhac.Text.Trim()
                p.NgayBatDauKinhDoanh = txtNgaybatdaukinhdoanh.Text.Trim()
                p.DienThoaiBan = txtDienthoaiban.Text.Trim()
                data.SaveChanges()
                'Insert_App_Log("Insert NguoiNopThue:" & txtTitle.Text.Trim & "", Function_Name.NguoiNopThue, Audit_Type.Create, Request.ServerVariables("REMOTE_ADDR"), Session("UserName"))
                Excute_Javascript("Alertbox('Cập nhật dữ liệu thành công.');window.location ='../../Page/NguoiNopThue/List.aspx';", Me.Page, True)
            Catch ex As Exception
                log4net.Config.XmlConfigurator.Configure()
                log.Error("Error error " & AddTabSpace(1) & Session("Username") & AddTabSpace(1) & "IP:" & GetIPAddress(), ex)
                Excute_Javascript("Alertbox('Cập nhật thất bại.');", Me.Page, True)
            End Try
        End Using
    End Sub
    Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
        ShowData()
    End Sub
    Protected Sub btnBack_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnBack.Click
        Response.Redirect("List.aspx")
    End Sub
#End Region
End Class
